/* eslint-disable arrow-parens */
import vue from "@vitejs/plugin-vue"; // 使用 Vue 插件
import path from "path";
import { defineConfig, loadEnv } from "vite";
import svgr from "vite-plugin-svgr";
import VueDevTools from 'vite-plugin-vue-devtools'
import autoprefixer from 'autoprefixer'
import tailwind from 'tailwindcss'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd()); // 获取 .env 文件里的环境变量
  return {
    base: env.VITE_PUBLIC_PATH, // 打包使用 / 开发环境使用 ./
    css: {
      postcss: {
        plugins: [tailwind(), autoprefixer()],
      },
      preprocessorOptions: {
        scss: {
          api: "modern-compiler", // or 'modern'
        },
      },
    },
    plugins: [
      vue(),
      VueDevTools(),
      svgr({
        // 使用 Vue 插件代替 React 插件
        include: "src/icons/*.svg",
      }),
    ],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"), // 定义路径别名
      },
    },
    server: {
      host: "0.0.0.0", // 允许外部访问
      proxy: {
        // 配置代理 '/java' 路由
        "^/java(.*)": {
          target: `http://${env.VITE_JAVA_IP}`,
          rewrite: (path) => path.replace(/^\/java/, ""),
        },
        // 配置代理 '/python' 路由
        "^/python(.*)": {
          target: `http://${env.VITE_PYTHON_IP}`,
          rewrite: (path) => path.replace(/^\/python/, ""),
        },
      },
    },
    worker: {
      format: 'es',
    },
  };
});
